package util;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import pojo.SysUser;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class SysInterceptor extends HandlerInterceptorAdapter {
    private Logger logger=Logger.getLogger(SysInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        StringBuffer requestURL = request.getRequestURL();
        if (requestURL.indexOf("/user/login")!=-1||requestURL.indexOf("/user/toLogin")!=-1){
            return true;
        }

        SysUser userSession = (SysUser) request.getSession().getAttribute("userSession");
        if (userSession!=null){
            return true;
        }
        response.sendRedirect(request.getContextPath()+"/401.jsp");
        return false;
    }
}
